<template>
  <el-dialog title="零售价调价详情" :close-on-click-modal="false" :visible.sync="visible" center fullscreen>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form :model="dataForm" ref="dataForm" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="单据编号" prop="billId">
            <el-input v-model="dataForm.billId" readonly />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="生效日期" prop="effectiveTime">
            <el-input v-model="dataForm.effectiveTime" readonly>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="制单人" prop="createUserName">
            <el-input v-model="dataForm.createUserName" readonly>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="制单日期" prop="createTime">
            <el-input v-model="dataForm.createTime" readonly>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="memo" read-only>
            <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="dataForm.memo"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" header-cell-class-name="miui-header-cell-style" @selection-change="handleSelectionChange">
      <el-table-column prop="goodsCode" label="商品代码"></el-table-column>
      <el-table-column prop="goodsName" label="商品名称"></el-table-column>
      <el-table-column prop="oldPrice" label="现销售价"> </el-table-column>
      <el-table-column prop="newPrice" label="调整价格"> </el-table-column>
    </el-table>
  </el-dialog>
</template>

<script>
  import { getAdPriceObj } from "@/api/eims/retail-price-adjust"
  import { fetchDetailList, getDetailById } from "@/api/eims/retail-price-adjust-detail"
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          applyStatus: "2",
          ctgId: "",
          ctgName: "",
          supplyId: "",
          supplyName: "",
          memo: "",
          detailList: []
        },
        ctgOptions: [],
        dataList: [],
        dataListLoading: false,
        supplySearchVisible: false,
        goodsListVisible: false,
        selectionList: []
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.dataForm.supplyId = ""
        this.visible = true
        this.dataList = []
        this.$nextTick(() => {
          this.$refs["dataForm"].resetFields()
          if (this.dataForm.id) {
            this.dataListLoading = true
            getAdPriceObj(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data.data
                this.dataList = response.data.data.data.list
              }else{
                this.$message.error(response.data.msg)
              }
              this.dataListLoading = false
            })
          }
        })
      },
      //更新表单数据
      updateFormData(data) {
        this.dataList = data
        data.forEach(item => {
          let list = []
          list.push({
            goodsId: item.id
          })
          this.dataForm.detailList = list
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs["dataForm"].validate(valid => {
          if (valid) {
            this.dataForm.detailList.forEach((item, index) => {
              item.applyQuantity = this.dataList[index].applyQuantity
            })
            receiveApplyAddObj(this.dataForm).then(result => {
              if(response.data.code == '0'){
                this.dataForm.applyStatus == "1" ?
                  this.$message.success("新增并审核成功") :
                  this.$message.success("新增成功")
                this.visible = false
                this.$emit("refreshDataList")
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
